<html>
<head>
	<meta charset='utf-8' />
	<title>后台管理</title>
	<meta http-equiv="keywords" content="求职,招聘,房屋,出租,出售,求租,求购,宠物,二手,二手车,二手物品,旧货,寻物,寻人,出兑,外兑"> 
	<meta http-equiv="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息">  
	<meta name="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息"/>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#nav_bottom{width:98%;margin:0 auto}
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#nav_bottom{width:450px;margin:0 auto}
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		.info_item{color:#444;margin:15px 0;display:flex}
		.info_item > div:last-child{flex:1}
	</style>
</head>
<body style='padding:0;margin:0;background:#eee'>
<!-- 1 Content容器 -->
<div id='Content'>
	<!-- 3 内容区-->
	<div style='margin:10px 0;word-break:break-all;padding:10px;'>
		<div style='float:right;text-align:right' onclick='After_Admin_Exit()'>退出</div>

		<h2 style='text-align:center;'>后台管理-成员管理</h2>
		
	

		<div style='margin:10px auto'>
			<span id='after_fun_select'>

			</span>
			<span style='float:right'>
				<button id='admin_user_add_btn'>新增管理员</button>
			</span>
		</div>
		<div id='admin_user_add_area' style='display:none'>
			新增管理员：
			<div>
				用户名：<input type="text" id='admin_user_add_inp' />
			</div>
			<div>
				说　明：<input type="text" id='admin_user_add_inp_explain' />
			</div>
			<button id='admin_user_add_sub'>提交</button>
			<button id='admin_user_add_back'>返回</button>
		</div>

		<hr>

		<!--列表区-->
		<div id='user_list'></div>




		<!--修改密码浮动区-->
		<div id='user_pwd_change_area' style='position:fixed;top:200px;border:1px solid #AAA;background:#fff;padding:50px;display:none'>
			设置密码：
			<input type="password" id='user_pwd_change_inp' />
			<button id='user_pwd_change_sub'>提交</button>
			<button id='user_pwd_change_back'>返回</button>
		</div>

		<div style='height:100px;'></div>
	</div>	<!-- 3 内容区结束-->	

</div><!-- 1 Content容器结束 -->







<!--底部导航容器-->
<div id='Nav_Bottom' style='position:fixed;bottom:0;width:100%;height:45px'>



</body>
</html>


<script src='./Public/jquery.js'></script>
<script src='./Public/fun.js'></script>
<script>
	Check_After_User_Cookie();	//检测登陆状态

	
	var priv_name = 'after_set_user';
	Priv_Check(priv_name,function(res){
		if(res != 'ok'){
			alert('没有权限!');
			//location.href = document.referrer;
			exit;
		}
	});

	After_Fun_Select();	//加载后台设置页中的功能选择





	var uid;


	//加载底部导航栏
	Load_NavBottom('after');

	$(function(){
		//获取管理员列表
		After_Get_User_List();




		//### 新增管理员相关
		$('#admin_user_add_btn').click(function(){
			var priv_name = 'AfterSetUser_AddUser';
			Priv_Check(priv_name,function(res){
				if(res != 'ok'){
					alert('没有权限!');
					//location.href = document.referrer;
					exit;
				}
			});
			$(this).hide();
			$('#admin_user_add_area').show();
		});

		//提交
		$('#admin_user_add_sub').click(function(){
			var user = $('#admin_user_add_inp').val().trim();
			var explain = $('#admin_user_add_inp_explain').val().trim();
			if(!user){
				alert('不得为空！');return;
			}
			user = ChangeChar(user);
			explain = ChangeChar(explain);
			var type = 'admin_user_add';
			Token(type,function(token){
				$.ajax({
					url:url,
					type:'post',
					data:{
						token:token,
						type:type,
						user:user,
						explain:explain
					},
					success(res){
						switch(res){
							case 'err2':
								alert('该用户名已存在！');
								break;
							case 'ok':
								alert('用户添加成功！');
								location.reload(1);
								break;
						}
					}
				});
			});
		});

		//返回
		$('#admin_user_add_back').click(function(){
			$('#admin_user_add_area').hide();
			$('#admin_user_add_btn').show();
		});





	});


	//### 修改密码相关
	function user_pwd_change(id){
		var priv_name = 'AfterSetUser_ChangeUserPwd';
		Priv_Check(priv_name,function(res){
			if(res != 'ok'){
				alert('没有权限!');
				//location.href = document.referrer;
				exit;
			}
		});
		$('#user_pwd_change_inp').val('');
		uid = id;
		$('.user_con_btns').hide();
		$('#user_pwd_change_area').show();
	}
	//返回
	$('#user_pwd_change_back').click(function(){
		$('.user_con_btns').show();
		$('#user_pwd_change_area').hide();
	});
	//提交 
	$('#user_pwd_change_sub').click(function(){
		var pwd = $('#user_pwd_change_inp').val().trim();
		var type = 'after_change_user_pwd';
		Token(type,function(t){
			$.ajax({
				url:url,
				type:'post',
				data:{
					token:t,
					type:type,
					uid:uid,
					pwd:pwd
				},
				success(res){
					if(res == 'ok'){
						alert('密码设置成功！');
						$('.user_con_btns').show();
						$('#user_pwd_change_area').hide();
					}else{
						alert('密码设置失败！');
					}
				}
			});
		});
	});




	//删除管理员
	function After_User_Del(uid){
		var priv_name = 'AfterSetUser_DelUser';
		Priv_Check(priv_name,function(res){
			if(res != 'ok'){
				alert('没有权限!');
				//location.href = document.referrer;
				exit;
			}
		});

		if(!confirm('确认删除该用户?')){
			return;
		}
		var type = 'After_User_Del';
		Token(type,function(t){
			$.ajax({
				url:url,
				type:'post',
				data:{
					token:t,
					type:type,
					uid:uid
				},
				success(res){
					if(res == 'ok'){
						alert('删除成功!');
						After_Get_User_List();
					}else{
						alert('删除失败!');
					}
				}
			});
		});
	}

	//设置用户的所属组
	function User_Ground_Change(uid,uname,gid){
		if(gid){
			var gid_str = '&gid='+gid;
		}else{
			var gid_str = '';
		}
		location.href='after_set_user_change_group.html?uid='+uid+'&uname='+uname+gid_str;
	}












	//获取管理员列表 
	function After_Get_User_List(){
		$('#user_list').html('');
		var type = 'After_Get_User_List';
		Token(type,function(t){
			$.ajax({
				url:url,
				type:'post',
				data:{
					token:t,
					type:type
				},
				success(res){
					if(res == 'err'){
						return;
					}
					var user_list = JSON.parse(res);
					var str = '';
					for(var i=0;i<user_list.length;i++){
						str += "<div style='border-bottom:1px solid #ccc;margin:5px auto;padding-bottom:20px;'>";
						str += "<div>用户名："+user_list[i][1]+"</div>";
						str += "<div>备　注："+user_list[i][5]+"</div>";
						str += "<div>所属组："+user_list[i][3]+"</div>";
						str += "<div>创建时间："+user_list[i][4]+"</div>";
						str += "<div style='text-align:right' class='user_con_btns'>";
						str += "<button onclick=user_pwd_change("+user_list[i][0]+")>修改密码</button>";
						if(user_list[i][2]){
							str += " <button onclick=User_Ground_Change("+user_list[i][0]+",'"+user_list[i][1]+"','"+user_list[i][2]+"')>设置权限组</button> ";
						}else{
							str += " <button onclick=User_Ground_Change("+user_list[i][0]+",'"+user_list[i][1]+"')>设置权限组</button> ";
						}
						str += "<button onclick=After_User_Del("+user_list[i][0]+")>删除</button>";
						str += "</div>";
						str += "</div>";
					}
					$('#user_list').html(str);

				}
			});
		});
	}

</script>

